from django.contrib import admin

from badd.custom_site import custom_site
from badd.base_admin import BaseAdmin
from .models import Link, SideBar


@admin.register(Link, site=custom_site)
class LinkAdmin(BaseAdmin):
    list_display = [
        'title',
        'href',
        'status',
        'weight',
        'owner',
        'created_time'
    ]
    fields = ('title', 'href', 'status', 'weight')

    def save_model(self, request, obj, form, change):
        obj.owner = request.user
        return super(LinkAdmin, self).save_model(request, obj, form, change)


@admin.register(SideBar, site=custom_site)
class SideBarAdmin(BaseAdmin):
    list_display = [
        'title',
        'display_type',
        'content',
        'status',
        'owner',
        'created_time'
    ]
    fields = ('title', 'display_type', 'status', 'content')

    def save_model(self, request, obj, form, change):
        obj.owner = request.user
        return super(SideBarAdmin, self).save_model(request, obj, form, change)
